package testSom;

import java.util.*;
import java.util.stream.Collectors;

public class TestMerge {

    public static void main(String[] args) {
        Map<Integer, List<String>> map = new HashMap<>();

        String[] datas = new String[] {
                "hello",
                "aassc",
                "asc",
                "awe",
                "cccss",
                "aed"
        };
        for (String data : datas) {
            map.merge(data.length(), List.of(data), TestMerge::addNext);
        }
        System.out.println(map);
        Map<Integer, List<String>> collect = Arrays.stream(datas).collect(Collectors.groupingBy(String::length));
        System.out.println(collect);
    }

    private static List<String> addNext( List<String> datas, List<String> pre) {
        List<String> result = new ArrayList<>(datas);
        result.addAll(pre);
        return result;
    }

}
